<template>
  <el-dialog title="人员" :visible.sync="open" width="1000px" :close-on-click-modal="false" :show-close="false">
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="学生id" prop="studentsId">
          <el-input
            v-model="queryParams.studentsId"
            placeholder="请输入学生id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="社会活动id" prop="trainings">
          <el-input
            v-model="queryParams.trainings"
            placeholder="请输入社会活动id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-check" :disabled="multiple" size="mini" @click="handleSelect">选择</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button  type="warning" plain icon="el-icon-close" size="mini" @click="cancel">取消</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="trainingsList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="ID" align="center" prop="id" />
        <el-table-column label="学生id" align="center" prop="studentsId" />
        <el-table-column label="社会活动id" align="center" prop="trainings" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"

            >选择</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />


    </div>
  </el-dialog>
</template>

<script>
import { listTrainings, getTrainings, delTrainings, addTrainings, updateTrainings } from "@/api/village/studentstrainings";

export default {
  name: "Trainings",
  props: {
    open: {
      type: Boolean,
      default: false,
    }

  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生社会培训关联表格数据
      trainingsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentsId: null,
        trainings: null
      },
      // 表单参数
      selectedform: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleSelect(){

    },
    /** 查询学生社会培训关联列表 */
    getList() {
      this.loading = true;
      listTrainings(this.queryParams).then(response => {
        this.trainingsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.selectedform = [];
      this.$emit('onCancel')
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        studentsId: null,
        trainings: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

  }
};
</script>
